package com.hp.attendance.serlvet.attendanceCardSupplement;

import com.hp.attendance.entity.Card;
import com.hp.attendance.service.CardService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;
import java.io.IOException;
import java.sql.SQLException;


@WebServlet("/updateCard")
public class cardServlet extends HttpServlet {
    private CardService cardService=new CardService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String employee_number = req.getParameter("employee_number");
        String name = req.getParameter("name");
        String date = req.getParameter("date");
        Card card = new Card();
        card.setEmployee_number(Integer.valueOf(employee_number));
        card.setName(name);
        card.setDate(date);
        card.setType("未审批");
        try {
            cardService.addCard(card);
            req.getRequestDispatcher("/welcome").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
